<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
</head>
<body>
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">添加融资</h4>
        </div>
        <form style="padding:4%;height:500px;overflow-y:auto;" id="addFinancingForm" >
            <input type="hidden" value="{:I('get.teamId')}" name="team_id" />
            <div class="form-group">
                <label for="recipient-name" class="control-label"><span style="color:red;">*</span>投资人:</label>
                <input type="text" class="form-control" name="investor" value="" >
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label"><span style="color:red;">*</span>投资金额(元):</label>
                <input type="text" class="form-control" name="amount" >
                <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label"><span style="color:red;">*</span>融资轮次:</label>
                <input type="text" class="form-control" name="financing_no" >
                <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label"><span style="color:red;">*</span>占股比例(%):</label>
                <input type="text" class="form-control" name="ratio" >
                <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label"><span style="color:red;">*</span>投资日期:</label>
                <div class='input-group date' id='settledTime'>
                <input type="text" name="investment_time" class="form-control datetimepicker" data-date-format="yyyy-mm-dd" >
                    <span class="input-group-addon">
                                                <span class="glyphicon glyphicon-calendar"></span></span>
                <div class="help-block with-errors"></div>
                </div>

            </div>
            <div class="form-group">
                <label for="email" class="control-label">备注:</label>
                <input type="text" id="email" class="form-control" name="remark" >
                <div class="help-block with-errors"></div>
            </div>
        </form>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            <button type="button" id="saveFinancing" class="btn btn-primary">保存</button>
        </div>
    </div>
</div>

<script>

    $('.datetimepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        language: 'ch',
        pickDate: true,
        pickTime: false,
        autoclose: true,
        minView: 2,
        //pickerPosition:"bottom-left"
    });

    $("#saveFinancing").click(function(){
        if(!validateFinancingForm()){
            return false;
        };
        $.ajax({
            url:"{:U('Admin/Space/Settled/doAddFinancing')}",
            type:"post",
            dataType:"json",
            data:$("#addFinancingForm").serialize(),
            success:function(data){
                if(data){
                        $("#commonModal").modal('toggle');
                        common.alert("提示", "团队融资信息添加成功!", function () {
                            common.reload();
                        });
                    }else{
                        common.alert("提示", data.msg)
                    }
            }
        });
    });

    function validateFinancingForm() {
        $('#addFinancingForm').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                //invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                investor: {
                    validators: {
                        notEmpty: {
                            message: '投资人不能为空'
                        }
                    }
                },
                amount: {
                    validators: {
                        notEmpty: {
                            message: '投资金额不能为空'
                        },
                        regexp: {
                            regexp: /((^[1-9]+[0-9]*)|^0)(\.\d{0,2})?$/,
                            message: '投资金额必须为数字，最多2位小数'
                        }
                    }
                },
                financing_no: {
                    validators: {
                        notEmpty: {
                            message: '融资轮次不能为空'
                        }
                    }
                },
                ratio: {
                    validators: {
                        notEmpty: {
                            message: '占股比例不能为空'
                        },
                        regexp: {
                            regexp: /((^[1-9]+[0-9]*)|^0)(\.\d{0,2})?$/,
                            message: '占股比例必须为数字，最多2位小数'
                        }
                    }
                },
                investment_time: {
                    validators: {
                        notEmpty: {
                            message: '投资日期不能为空'
                        }
                    }
                }
            }
        });
        var data = $('#addFinancingForm').data('bootstrapValidator');
        if (data) {
            data.validate();
            if (!data.isValid()) {
                return false;
            }
        }
        return true;
    }
</script>